import { getAntd,getLabel, getEcCom } from './convert';
import store from '../../stores/index';
export const Meeting_PC = {
  showMessage: function(msg, type=1, duration=1.5){
      const message = window.antd.message;
      if(type === 1)      //警告
          message.warning(msg, duration);
      else if(type === 2)     //错误
          message.error(msg, duration);
      else if(type === 3)     //成功
          message.success(msg, duration);
      else    //普通信息
          message.info(msg, duration);
  },
  showConfirm: function(content, okEvent, cancelEvent, otherInfo={}){
      const { Modal } = getAntd();
      Modal.confirm({
          title: otherInfo.title || getLabel(131329,'信息确认'),
          content: React.createElement("div", {dangerouslySetInnerHTML:{__html:content}}),
          okText: otherInfo.okText || getLabel(826,'确定'),
          cancelText: otherInfo.cancelText || getLabel(201,'取消'),
          onOk() {
              typeof okEvent === "function" && okEvent();
          },
          onCancel() {
              typeof cancelEvent === "function" && cancelEvent();
          },
      });
  },
  callApi:function(url,params,method){
    const { WeaTools } = getEcCom();
    return WeaTools.callApi(url, method, params);
  },

  callApi2:function(url,params,method,successCallback,failCallback){
    const { WeaTools } = getEcCom();
    WeaTools.callApi(url, method, params).then((data)=>{
      if(data.status == true){
        typeof successCallback =='function'?successCallback():''
      }else{
        typeof failCallback =='function'?failCallback():''
      }
    })
  },
  getDialogFieldValue:function(fieldid){
    //获取当前是创建还是查看
    const {meetingDialog} = store;
    const {meetingId} = meetingDialog.dialogStatus;
    let form = {};
    meetingDialog.dialogStatus.type == 'create'?form = meetingDialog.form['create']:form=meetingDialog.form[meetingId];
    if(form&&form.isFormInit){
      const values = form.getFormParams();
      return values[fieldid];
    }
  },
  updateDialogFieldValue:function(fieldid,valObj){
    //获取当前是创建还是查看
    const {meetingDialog} = store;
    const {meetingId} = meetingDialog.dialogStatus;
    let form = {};
    meetingDialog.dialogStatus.type == 'create'?form = meetingDialog.form['create']:form=meetingDialog.form[meetingId];
    if(form&&form.isFormInit){
      form.updateFields({
        [fieldid]:valObj
      })
    }
  },
  setFormAttr:function(fieldid,attr={}){
    const {meetingDialog} = store;
    const {doNewForm, changeNewForm,dialogStatus} = meetingDialog;
    const {meetingId,conditions,type} = dialogStatus;
    let form = {};
    let conditionsTemp = {};
    let condition = [];
    meetingDialog.dialogStatus.type == 'create'?form = meetingDialog.form['create']:form=meetingDialog.form[meetingId];
    meetingDialog.dialogStatus.type == 'create'?conditionsTemp = conditions['create']:conditionsTemp=conditions[meetingId];
    if(form&&form.isFormInit && fieldid && conditionsTemp){
      conditionsTemp.map(c => {
        let tempC = {}
        let itemsTemp = []
        c && c.items && c.items.map(fields => {
          if(fields.domkey[0] == fieldid){
            fields = {...fields,...attr}
          }
          itemsTemp.push(fields)
        })
        tempC = {item:itemsTemp,defaultshow:c.defaultshow,title:c.title}
        condition.push(tempC);
      })
      doNewForm(type, (form) => {
        form.initFormFields(condition)
        changeNewForm(true)
      })
      // meetingDialog.dialogStatus.type == 'create'?(meetingDialog.form={...meetingDialog.form,'create':form}):(meetingDialog.form={...meetingDialog.form,[meetingId]:form})
    }
  }
}

const meetingInterface = {...Meeting_PC};

window.meetingBase = meetingInterface;